package goover.unit03;

import java.util.TreeSet;

public class TreeSetDemo02 {
    public static void main(String[] args){
        TreeSet ts = new TreeSet();
        ts.add(new Teacher(1,"zhangsan"));
        ts.add(new Teacher(3,"zhangsan"));
        ts.add(new Teacher(3,"lisi"));
        System.out.println(ts);
        for(Object o : ts){
            System.out.println(o);
        }
    }
}
class Teacher implements Comparable{
    int id;
    String name;

    public Teacher(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
    @Override
    public int compareTo(Object o) {
        Teacher s = (Teacher)o;
        if(this.id - s.id > 0){
            return  1;
        }
        if(this.id - s.id == 0){
            return  this.name.compareTo(s.name);
        }
        return -1;
    }
}